﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="pgNuevoExpediente.aspx.cs" Inherits="EGuayas.Web.Auditoria.Admin.Otro.pgNuevoExpediente" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="~/Resources/css/Style.css" rel="stylesheet" />
    <!-- Load Ext JS -->
    <script src="../../../Resources/js/Global.js"></script>
    <script>
       
        
    </script>
</head>
<body>
    <form  Id="frmAudOts" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server"></ext:ResourceManager>
        <ext:Viewport ID="vipContenedor" runat="server" Layout="FitLayout">
            <Items> 
                <ext:Hidden Text="" ID="hdIdGlobalOts" runat="server" />  
                <ext:Panel ID="Panel1" 
                runat="server" 
                Region="Center" 
                Margins="5 5 5 0"
                AutoScroll="true"
                Layout="VBoxLayout">
                <LayoutConfig>
                    <ext:VBoxLayoutConfig Align="Stretch" />
                </LayoutConfig>
                <Items>
                          <ext:FormPanel 
                           ID="frmAuditoria" 
                           runat="server" 
                           Border="false"
                           ButtonAlign="Center"
                           BodyStyle="background-color:#B6C1A6;"
                           BodyPadding="10"
                           Height="250"
                           Layout="Form">
                           <Items>
                                    
                                    <ext:TextField ID="txtNombre"  runat="server"  Name ="Nombre"   FieldLabel ="Nombre del Expediente:" LabelAlign="Top" AnchorHorizontal="85%" AllowBlank="false" ReadOnly="true"></ext:TextField>
                                    <ext:TextArea  ID="txtDescrip" runat="server"  Name ="Descrip"  FieldLabel ="Descripción" LabelAlign="Top" AnchorHorizontal="85%" ReadOnly="true"></ext:TextArea>
                                  
                                    <ext:DateField 
                                        ID="dtFechaInicio" 
                                        runat="server" 
                                        MsgTarget="Side" 
                                        AllowBlank="false"
                                        FieldLabel="Fecha Inicio" 
                                        Name="FechaInicio"
                                        Vtype="daterange" 
                                        EndDateField="dtFechaFin"
                                        EnableKeyEvents="true"
                                        />
                                     <ext:DateField 
                                        ID="dtFechaFin" 
                                        runat="server" 
                                        MsgTarget="Side" 
                                        AllowBlank="false"
                                        FieldLabel="Fecha Fin"
                                        Name="FechaFin"
                                        Vtype="daterange"
                                        StartDateField="dfFechaInicio"
                                        EnableKeyEvents="true" 
                                        />                                       
                           </Items>
                           <Listeners>
                                    <ValidityChange Handler="#{btnSave}.setDisabled(!valid);" />
                           </Listeners>
                           <Buttons>
                              <ext:Button ID="btnSave" runat="server" Text="Aceptar" Disabled="true">
                                <DirectEvents>
                                    <Click OnEvent="btnSave_Click">
                                        <ExtraParams>
                                            <ext:Parameter Name="prmValues" Value="Ext.encode(#{frmAuditoria}.getForm().getValues())" Mode="Raw" />
                                        </ExtraParams>
                                        <EventMask ShowMask="True"></EventMask>
                                    </Click>
                                </DirectEvents>
                              </ext:Button>
                            <ext:Button ID="btnClosePlus" runat="server" Text="Cerrar"  OnClientClick="window.parent.App.CloseNuevoExpediente();">
                                <Listeners>                    
                                </Listeners>
                           </ext:Button>
                           </Buttons>  
                         </ext:FormPanel>

                  <ext:Panel ID="pnlGlobalDocAdd" runat="server" Layout="BorderLayout"
                         Height="300"
                         Title="Solicitud de documentos adicionales"  Icon ="PastePlain">
                       
                        <items>
                        <ext:FormPanel 
                            ID     ="fmpDocDatos" 
                            runat  ="server" 
                            Region ="North"
                            Title  ="Datos Documento Adicional"
                            Margins="0 5 5 5"                                             
                            Width  ="300"                          
                        
                            BodyStyle="background-color:transparent;padding:5px 5px 0;"                          
                            Layout="HBoxLayout">                            
                            <FieldDefaults LabelAlign="Left"  MsgTarget="Side" />
                            <Defaults>
                              
                                <ext:Parameter Name="Flex" Value="1" />
                                <ext:Parameter Name="Layout" Value="anchor" />
                            </Defaults>
                            <Items>  
                                          
                                           <ext:Hidden Text="" ID="hddnIndex" runat="server" Name="Index" />     
                                           <ext:Hidden Text="" ID="hddnId" runat="server" Name="Id" />            
                                           <ext:TextField ID="tfNombreFrm" runat="server" FieldLabel="Nombre" Name="Nombre"    AllowBlank="false"/>
                                           <ext:RadioGroup ID="rdgSiNoFrm" Name="Obligacion" 
                                                        GroupName="rdgSiNo_group"
                                                        runat="server"
                                                        AllowBlank="false"
                                                        Vertical="false" 
                                                        FieldLabel="Obligatorio">
                                                        <LayoutConfig>
                                                            <ext:CheckboxGroupLayoutConfig AutoFlex="false" />                                                          
                                                        </LayoutConfig>
                                                        <Defaults>
                                                            <ext:Parameter Name="name" Value="ccType" /> 
                                                            <ext:Parameter Name="style" Value="margin-right:10px;" />                                                         
                                                        </Defaults>
                                                        <Items>
                                                          
                                                            <ext:Radio ID="Radio3"
                                                                runat="server"
                                                                InputValue="S"
                                                                BoxLabel="Si" />

                                                            <ext:Radio ID="Radio4"
                                                                runat="server"
                                                                InputValue="N"
                                                                BoxLabel="No" />  
                                   
                                                        </Items>
                                           </ext:RadioGroup>
                                           <ext:ComboBox ID="cbbTipoFrm" runat="server" FieldLabel="Tipo" ValueField="Id" 
                                               Editable="false"
                                               DisplayField="Nombre"    AllowBlank="false" Name="Formato">
                                                            <Store>
                                                                <ext:Store runat="server" ID="stoTipoFrm">
                                                                    <Model>
                                                                        <ext:Model ID="Model4" runat="server" IDProperty="Id">
                                                                            <Fields>
                                                                                <ext:ModelField Name="Id"></ext:ModelField>
                                                                                <ext:ModelField Name="Nombre"></ext:ModelField>
                                                                            </Fields>
                                                                        </ext:Model>
                                                                    </Model>
                                                                </ext:Store>
                                                            </Store>
                                                            <Triggers>
                                                                <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                                                            </Triggers>
                                                            <Listeners>
                                                                <Select Handler="this.getTrigger(0).show();" />
                                                                <BeforeQuery Handler="this.getTrigger(0)[this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                                                                <TriggerClick Handler="if (index == 0) { 
                                                               this.clearValue(); 
                                                               this.getTrigger(0).hide();
                                                           }" />
                                                            </Listeners>
                                            </ext:ComboBox>
                            </Items>
                           <Listeners>
                                <ValidityChange Handler="
                                    #{btnSaveRecord}.setDisabled(!valid);
                                    #{btnUpdateRecord_1}.setDisabled(!valid);
                                    #{btnUpdateRecord_2}.setDisabled(!valid);
                                    " />
                            </Listeners>
                            <Buttons>
                                  <ext:Button 
                                            ID="btnLimpiar" 
                                            runat="server" 
                                            Icon="Erase"                                          
                                            Text="Limpiar" > 
                                               <Listeners>
                                                   <Click Handler="wucJsPgAudOts.ClearDataGrid()" > </Click>
                                               </Listeners>                                  
                                        </ext:Button>
                                        <ext:Button 
                                            ID="btnSaveRecord" 
                                            runat="server"  
                                            Text="Agregar" 
                                            Icon="FolderAdd"                                          
                                            Disabled="true"> 
                                               <Listeners>
                                                   <Click Handler="wucJsPgAudOts.AddDataGrid()" > </Click>
                                               </Listeners>                                  
                                        </ext:Button>
                                         <ext:Button  
                                           ID="btnUpdateRecord_1" runat="server" Text="Actualizar" 
                                           Icon ="FolderExplore"
                                           Hidden="true"> 
                                               <Listeners>
                                                   <Click Handler="wucJsPgAudOts.UpdateDataGrid()" ></Click>
                                               </Listeners>                                  
                                        </ext:Button>
                                         <ext:Button ID="btnUpdateRecord_2" runat="server" Text="Actualizar" 
                                           Icon ="FolderEdit"                                       
                                           Hidden="true">
                                          <DirectEvents>
                                            <Click OnEvent="btnUpdate_Click"  After="wucJsPgAudOts.ClearDataGrid();">
                                                <ExtraParams>
                                                      <ext:Parameter Name="Values" Value="Ext.encode(#{fmpDocDatos}.getForm().getValues())" Mode="Raw" />                                       
                                                </ExtraParams>
                                             <EventMask ShowMask="true"></EventMask></Click>
                                        </DirectEvents>
                                </ext:Button>    
                                       
                             </Buttons>
                         </ext:FormPanel>  
                        <ext:GridPanel 
                            ID="gdDocAdd"    
                            Region="Center"
                            runat="server" 
                            Title="Documentos Adicionales Agregados"
                            Margins="0 0 5 5"                          
                            Flex="1"
                            ButtonAlign="Center"
                            DefaultAnchor="70%" 
                            Frame="true">
                            <Store>
                                <ext:Store 
                                    ID="stoDocAdd" 
                                    runat="server">
                                    <Model>
                                        <ext:Model ID="Model2" runat="server" IDProperty="Id">
                                            <Fields>
                                                <ext:ModelField Name="Id" />
                                                <ext:ModelField Name="Nombre" />
                                                <ext:ModelField Name="Formato" />
                                                <ext:ModelField Name="Obligacion" />
                                                <ext:ModelField Name="Nuevo" />
                                            </Fields>
                                        </ext:Model>
                                    </Model>
                                    <Proxy>
                                        <ext:PageProxy DirectFn="App.direct.BindDataAddArchivos">
                                            <Reader>
                                                <ext:JsonReader></ext:JsonReader>
                                            </Reader>
                                        </ext:PageProxy>
                                    </Proxy>
                                </ext:Store>
                            </Store>
                            <ColumnModel ID="ColumnModel2" runat="server">
                                <Columns>
                                    <ext:Column ID="Column7" runat="server" DataIndex="Nombre" Text="Nombre" Flex="1"></ext:Column>
                                    <ext:Column ID="Column8" runat="server" DataIndex="Obligacion" Text="Obligatorio" Width="150"> 
                                         <Renderer Fn="wucJsPgAudOts.renderSiNo" />
                                    </ext:Column>
                                    <ext:Column ID="Column9" runat="server" DataIndex="Formato" Text="Tipo" Width="150">                                           
                                    </ext:Column>
                                    <ext:ImageCommandColumn ID="ImageCommandColumn2" runat="server" Width="30" Sortable="false">
                                    <Commands>
                                        <ext:ImageCommand Icon="Decline" ToolTip-Text="Borrar" CommandName="delete">                            
                                        </ext:ImageCommand>
                                    </Commands>
                                    <Listeners>
                                        <Command Handler="wucJsPgAudOts.DeleteRowGrid(this,recordIndex,record.data);" />
                                    </Listeners>
                                </ext:ImageCommandColumn>
                                   <ext:ImageCommandColumn ID="ImageCommandColumn3" runat="server" Width="30" Sortable="false">
                                    <Commands>
                                        <ext:ImageCommand Icon="FolderEdit" ToolTip-Text="Editar" CommandName="edit">                            
                                        </ext:ImageCommand>
                                    </Commands>
                                    <Listeners>
                                        <Command Handler="wucJsPgAudOts.SelectRowGrid(this,recordIndex,record.data);" />
                                    </Listeners>
                                </ext:ImageCommandColumn>
                              </Columns>
                            </ColumnModel>
                            <SelectionModel>
                                <ext:CellSelectionModel ID="CellSelectionModel1" runat="server" />
                            </SelectionModel>
                            <Plugins>
                                <ext:CellEditing ID="CellEditing1" runat="server" ClicksToEdit="1" />
                                <ext:BufferedRenderer ID="BufferedRenderer3" runat="server" />
                            </Plugins>
                             <Buttons>
                                   <ext:Button ID="btnEnviar" runat="server" Text="Enviar">
                                    <DirectEvents>
                                        <Click OnEvent="btnEnviar_Click" Before="wucJsPgAudOts.ValidarGridAddDoc()">
                                            <ExtraParams>
                                                  <ext:Parameter Name="IdOts" Value="#{hdIdGlobalOts}.getValue()" Mode="Raw" />                                       
                                                  <ext:Parameter Name="Values" Value="Ext.encode(#{gdDocAdd}.getRowsValues({selectedOnly:false}))" Mode="Raw" />                                       
                                            </ExtraParams>
                                         <EventMask ShowMask="true"></EventMask></Click>
                                    </DirectEvents>
                                </ext:Button>
                             </Buttons>
                        </ext:GridPanel>
                
             
                      </items>
                    </ext:Panel>

                  
                     
             </Items>
            </ext:Panel>
        </Items>

        </ext:Viewport>
           <ext:XScript ID="XScript1" runat="server">
            <script type="text/javascript">
                var wucJsPgAudOts= new Object();
                //Panel Adicional Otros
                wucJsPgAudOts.renderSiNo = function (value) {
                    try{
                        var txtVal = "";
                      
                        switch (value) {
                            case "S": txtVal = "Si"; break;
                            case "N": txtVal = "No"; break;
                          
                        }
                        return Ext.String.format('<span>{0}</span>', txtVal);
                    } catch (jsbug) {
                        AppGlobalJs.showBug("wucJsPgAudOts.changeSiNO: " + jsbug);
                    }
                };
                wucJsPgAudOts.ClearDataGrid= function () {
                    try
                    {  
                        #{btnSaveRecord}.show(); 
                        #{btnUpdateRecord_1}.hide();  
                        #{btnUpdateRecord_2}.hide();  
                        #{fmpDocDatos}.getForm().reset();
                        #{btnEnviar}.enable();
                    } catch (jsbug) {
                        AppGlobalJs.showBug("wucJsTareas.ClearDataGrid: " + jsbug);
                    }
                };
                wucJsPgAudOts.AddDataGrid = function () {
                    try
                    {
                        if (#{hdIdGlobalOts}.getValue()!="")
                        {
                            var dataForm =#{fmpDocDatos}.getForm().getValues();
                            var _tipo =dataForm.Formato;
                            var _obli =dataForm.rdgSiNo_group;
                        
                            var info ={Id:'',Nombre:dataForm.Nombre,Formato:_tipo,Obligacion:_obli,Nuevo:true};
                            #{stoDocAdd}.add(info); 
                            #{fmpDocDatos}.getForm().reset();
                            #{btnEnviar}.enable();
                        }
                        else
                        {
                            Ext.Msg.show({
                                title: 'Error',
                                msg: 'Se requiere se almacene información relacionada a Auditoria previamente',
                                buttons: Ext.Msg.ERROR,                   
                                animEl: 'elId'
                            });
                        
                        }

                    } catch (jsbug) {
                        AppGlobalJs.showBug("wucJsPgAudOts.AddDataGrid: " + jsbug);
                    }
                };
                wucJsPgAudOts.UpdateDataGrid= function() {
                    try
                    {
                        var dataForm = #{fmpDocDatos}.getForm().getValues();
                        var _tipo  = dataForm.Formato;
                        var _obli  = dataForm.rdgSiNo_group;  
                        var _index = parseInt(dataForm.Index);
                        var info = {Id:'',Nombre:dataForm.Nombre,Formato:_tipo,Obligacion:_obli,Nuevo:true};
                        var store    = #{gdDocAdd}.store;
                        store.removeAt(_index);
                        store.insert(_index,info);
                        wucJsPgAudOts.ClearDataGrid();
                    } catch (jsbug) {
                        AppGlobalJs.showBug("wucJsPgAudOts.UpdateDataGrid: " + jsbug);
                    }
                };
              
                wucJsPgAudOts.DeleteRowGrid= function (me,recordIndex,data) {
                    try
                    {
                        if (data.Nuevo==false)
                        {
                            Ext.Msg.confirm('Eliminar item', 'Desea eliminar item ?', function (btn) {
                                if (btn == 'yes') {  
                                    App.direct.DeleteDocumentoAdicional(data.Id,{
                                        success: function (result) {
                               
                                        },
                                        eventMask: {
                                            showMask: true,
                                            minDelay: 500
                                        }
                                    });
                                }                     
                            } ); 
                        }
                        else
                        {
                            me.up('gridpanel').store.removeAt(recordIndex);
                        }

                    } catch (jsbug) {
                        AppGlobalJs.showBug("wucJsPgAudOts.DeleteRowGrid: " + jsbug);
                    }
                };
                wucJsPgAudOts.SelectRowGrid= function (me,recordIndex,data) {
                    try
                    {
                        #{btnSaveRecord}.hide();
                      
                        #{fmpDocDatos}.getForm().setValues(data);
                        #{hddnIndex}.setValue(recordIndex);
                        #{rdgSiNoFrm}.setValue({rdgSiNo_group: data.Obligacion});

                        if (data.Id!='')
                        {
                            #{btnUpdateRecord_2}.show(); 
                        }
                        else
                        {
                            #{btnUpdateRecord_1}.show(); 
                        }

                    } catch (jsbug) {
                        AppGlobalJs.showBug("wucJsPgAudOts.SelectRowGrid: " + jsbug);
                    }
                };
                wucJsPgAudOts.ValidarGridAddDoc= function () {
                    try
                    {
                        var data =#{gdDocAdd}.getRowsValues({selectedOnly:false});
                        var done =(data.length!=0);
                        if (done==false)
                        {
                            Ext.Msg.show({
                                title: 'Error',
                                msg: AppLabelGlobalJs.loaddoc_num_doc_03,
                                buttons: Ext.Msg.ERROR,                   
                                animEl: 'elId'
                            });
                        }
                        return done;
                    } catch (jsbug) {
                        AppGlobalJs.showBug("wucJsPgAudOts.ValidarGridAddDoc: " + jsbug);
                    }
                };
                  </script>
        </ext:XScript>

    </form>
</body>
</html>
